<taglib name="Admin\TagLib\EasyUI" />

<easyui:datagrid options="datagrid.options" fields="datagrid.fields" />

<div id="content_newslist_datagrid_toolbar" style="padding:1px;height:auto">
	<form style="border-bottom:1px solid #ddd;margin-bottom:1px;padding:5px">		
		标题: 
		<input type="text" name="search[title]" style="width:100px;padding:2px"/>
		时 间: <input name="search[begin]" class="easyui-datebox" style="width:100px">
		至: <input name="search[end]" class="easyui-datebox" style="width:100px">
		
		<a href="javascript:;" onclick="contentNewsListDatagridSearch(this)" class="easyui-linkbutton" iconCls="icons-map-magnifier">搜索</a>
	</form>
	<div>
		<a href="javascript:;" class="easyui-linkbutton" data-options="plain:true,iconCls:'icons-arrow-add'" onclick="contentNewsListAdd()">添加</a>
		<a href="javascript:;" class="easyui-linkbutton" data-options="plain:true,iconCls:'icons-other-delete'" onclick="contentNewsListDelete()">删除</a>
		<a href="javascript:;" class="easyui-linkbutton" data-options="plain:true,iconCls:'icons-arrow-arrow_up'" onclick="contentNewsListOrder()">排序</a>
	</div>
</div>

<script type="text/javascript">
var content_newslist_datagrid_id = 'content_newslist_datagrid';
//排序格式化
function contentNewsListOrderFormatter(val, arr){
	return '<input class="content_gridlist_order_input" type="text" name="order['+arr['id']+']" value="'+ val +'" size="2" style="text-align:center">';
}
//时间格式化
function contentNewsListTimeFormatter(val, arr){
	return val == '1970-01-01 08:00:00' ? arr['inputtime'] : val;
}
//状态格式化
function contentNewsListStatusFormatter(val){
	return val == 1 ? '已发布' : '<font color="red">未发布</font>';
}
//操作格式化
function contentNewsListOperateFormatter(id){
	var btn = [];
	btn.push('<a href="javascript:;" onclick="contentNewsListEdit('+id+')">修改</a>');
	btn.push('<a href="javascript:;" onclick="contentNewsListDelete('+id+')">删除</a>');
	return btn.join(' | ');
}
//搜索
function contentNewsListDatagridSearch(that){
	var queryParams = $('#'+content_newslist_datagrid_id).datagrid('options').queryParams;
	$.each($(that).parent('form').serializeArray(), function() {
		queryParams[this['name']] = this['value'];
	});
	$('#'+content_newslist_datagrid_id).datagrid('reload');
}
//添加
function contentNewsListAdd(){
	var url = '<{:U('Content/add_news_iframe?catid='.$catid)}>';
	contentMainOpenUrl(url, true);
}
//编辑
function contentNewsListEdit(id){
	if(typeof(id) !== 'number'){
		$.messager.alert('提示信息', '未选择数据', 'error');
		return false;
	}
	var url = '<{:U('Content/edit_news_iframe?catid='.$catid)}>';
	url += url.indexOf('?') != -1 ? '&id='+id : '?id='+id;
	contentMainOpenUrl(url, true);
}
//删除
function contentNewsListDelete(id){
	var ids = [];
	if(!id){
		var obj = $('#'+content_newslist_datagrid_id).datagrid('getSelections');
		if(obj) for(var i = 0; i < obj.length; i++) ids.push(obj[i].id);
	}else{
		if(typeof(id) == 'number') ids.push(id);
	}
	if(ids.length == 0){
		$.messager.alert('提示信息', '未选择数据', 'error');
		return false;
	}
	$.messager.confirm('提示信息', '确定要删除吗？', function(result){
		if(!result) return false;
		$.post('<{:U('Content/delete_news?catid='.$catid)}>', {ids: ids}, function(res){
			if(!res.status){
				$.messager.alert('提示信息', res.info, 'error');
			}else{
				$.messager.alert('提示信息', res.info, 'info');
				$('#'+content_newslist_datagrid_id).datagrid('reload');
			}
		}, 'json');
	});
}
//排序
function contentNewsListOrder(){
	$.post('<{:U('Content/order_news?catid='.$catid)}>', $('.content_gridlist_order_input').serialize(), function(res){
		if(!res.status){
			$.messager.alert('提示信息', res.info, 'error');
		}else{
			$.messager.alert('提示信息', res.info, 'info');
			$('#'+content_newslist_datagrid_id).datagrid('reload');
		}
	}, 'json');
}